#多阶段构建 node基座+镜像源+git拉取+build部分
FROM node:16-alpine AS build-stage

# APK包使用阿里的镜像
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

#私有仓库账号 注意账户中带@用%40代替
ARG GIT_USERNAME=帐号
ARG GIT_PASSWORD=密码

RUN apk update && apk add git && git clone https://${GIT_USERNAME}:${GIT_PASSWORD}@gitee.com/gaogao520/xiaoduan-vue-press.git

WORKDIR xiaoduan-vue-press

RUN npm config set registry https://registry.npmmirror.com/ && npm install 

RUN npm run docs:build

# 使用官方的Nginx作为父镜像  
FROM nginx:stable-alpine AS production-stage

# 复制build后的文件到Nginx的html目录  
COPY --from=build-stage /xiaoduan-vue-press/docs/dist /usr/share/nginx/html  

# 复制自定义的Nginx配置文件  
COPY --from=build-stage /xiaoduan-vue-press/nginx.conf /etc/nginx/conf.d/default.conf 

EXPOSE 5200

# docker容器启动时执行的命令
CMD ["nginx", "-g", "daemon off;"]


